package com.song.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.song.config.RabbitConfig;
import com.song.domain.Product;
import com.song.entity.R;
import com.song.service.ProductService;
import io.swagger.models.auth.In;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author TonySong
 * @date 2024/6/15 0015
 * @time 10:01
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;
    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/list")
    public R  list(@RequestParam(name="offset",defaultValue = "1") Integer offset,
                   @RequestParam(name="size",defaultValue = "5")Integer size){
        return  R.success( this.productService.page(new Page<>(offset,size)));
    }

    @GetMapping("/{id}")
    public R findById(@PathVariable("id") Long id){
       return this.productService.findById(id);
    }

    @PostMapping("/")
    public R save(@RequestBody Product product){
          return  R.success(this.productService.save(product));
    }


}